package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsCouponUser;
import com.qf.service.DtsCouponUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/10/19 22:32
 */
@Service
public class DtsCouponUserServiceImpl implements DtsCouponUserService {

    @Autowired
    DtsCouponUserMapper couponUserMapper;

    @Override
    public Map<String, Object> selectlistuserByPage(Integer page, Integer limit, String sort, String order, Integer couponId, Integer status) {
        IPage<DtsCouponUser> iPage = new Page<>(page,limit);
        QueryWrapper<DtsCouponUser> wrapper = new QueryWrapper<>();

        if ("desc".equalsIgnoreCase(order)){
            wrapper.orderByDesc(sort);
        }else {
            wrapper.orderByAsc(sort);
        }
        if (couponId!=null){
            wrapper.eq("coupon_id",couponId);
        }
        if (status!=null){
            wrapper.eq("status",status);
        }

        couponUserMapper.selectPage(iPage,wrapper);

        Map<String, Object> map = new HashMap<>();
        map.put("total",iPage.getTotal());
        map.put("items",iPage.getRecords());

        return map;
    }
}
